//
//  SiHomeVC.swift
//  SiliUtility
//
//  Created by Li Dong on 2023/10/17.
//

import UIKit

enum HomeHandlerType {
    case S_Wallpaper
    case D_Wallpaper
    case Save
    case Eat
}

class SiHomeVC: SiBaseVC {

    @IBOutlet weak var settingBtn_top: NSLayoutConstraint!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        hideNavgaitionBar()
        settingBtn_top.constant = CGFloat.topPadding
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if AppProducts.shared.isPurchased {
            adHelper.removeBannerView()
        }else{
            if hasLoadAd {
                return
            }
            hasLoadAd = true
            adHelper.loadBanner(currentVC: self, isMainVC: false)
        }
    }

    @IBAction func settingClick(_ sender: Any) {
        navigationController?.pushViewController(SiSettingVC(), animated: true)
    }
    
    
    @IBAction func staticWalllaper(_ sender: Any) {
        homeHandler(type: .S_Wallpaper)
    }
    @IBAction func dynamicWallaper(_ sender: Any) {
        homeHandler(type: .D_Wallpaper)
    }
    
    @IBAction func saveClick(_ sender: Any) {
        homeHandler(type: .Save)
    }
    
    @IBAction func eatClick(_ sender: Any) {
        homeHandler(type: .Eat)
    }
    
    private func homeHandler(type: HomeHandlerType) {
        if !AppProducts.shared.isPurchased {
            showSubVC()
            return
        }
        switch type {
        case .S_Wallpaper:
            navigationController?.pushViewController(SiWebVC(url: AppConfig.H5_STAIC_WALLPAPER), animated: true)
            break
        case .D_Wallpaper:
            navigationController?.pushViewController(SiWebVC(url: AppConfig.H5_DYNAMIC_WALLPAPER), animated: true)
            break
        case .Save:
            navigationController?.pushViewController(SiSaveVC(), animated: true)
            break
        case .Eat:
            navigationController?.pushViewController(SiEatVC(), animated: true)
            break
        }
    }
    
}
